package com.ljx.funchat.common.exception;

import cn.hutool.http.ContentType;
import cn.hutool.json.JSONUtil;
import com.ljx.funchat.common.domain.vo.resp.ApiResult;
import io.netty.handler.codec.http.HttpRequest;
import lombok.AllArgsConstructor;
import org.apache.commons.io.Charsets;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@AllArgsConstructor
public enum HttpErrorEnum {

    ACCESS_DENIED(401, "登录失效请重新登录");

    private Integer httpCode;
    private String desc;

    /**
     * 发送状态信息
     * @param response
     * @throws IOException
     */
    public void sendHttpError(HttpServletResponse response) throws IOException {
        response.setStatus(httpCode);
        response.setContentType(ContentType.JSON.toString(Charsets.UTF_8));
        response.getWriter().write(JSONUtil.toJsonStr(ApiResult.fail(httpCode, desc)));
    }


}
